package antlr4.definitive.d4_expr.d4_5_1_xml.run;

import antlr4.definitive.d4_expr.d4_5_1_xml.gen.XMLLexer;
import cn.hutool.core.io.FileUtil;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.Token;

import java.util.List;


public class Xml {

    public static void main(String[] args) {
        if (args.length > 0) {
            String arg = args[0];
            String content = FileUtil.readString(arg, "UTF-8");
            System.out.println("读取文件" + arg + ",内容:\n" + content);
            CodePointCharStream input = CharStreams.fromString(content);
            System.out.println("开始解析文件");

            XMLLexer xmlLexer = new XMLLexer(input);
            List<? extends Token> allTokens = xmlLexer.getAllTokens();
            System.out.println(allTokens);

        } else {
            System.err.println("不推荐手写字符串，还是读取一个已经存在的文件吧");
        }
    }

}
